package com.example.usermanagement.publisher;

import com.example.usermanagement.events.LiuKaApplicationLogEvent;
import com.example.usermanagement.liuka.model.FlowUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author yha
 * @ClassName
 * @description:TODO
 * @date 2024年09月10日
 * @version: 1.0.0
 */
@Slf4j
@Service
public class ApplicationPush implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void push(FlowUser flowUser, BigDecimal flowSize){
        log.info("用户：{}，消耗流量:{}",flowSize);
        applicationEventPublisher.publishEvent(new LiuKaApplicationLogEvent(this, flowUser.getId(), flowSize));
    }
}
